package spring;

import java.util.Set;

/**
 * @ProjectName: Spring
 * @Package: spring
 * @ClassName: AnnotationConfigUtils
 * @Author: zxh
 * @Description:
 * @Date: 2022/3/11 8:22
 * @Version: 1.0
 */
public abstract class AnnotationConfigUtils {

    public static final String CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME =
            "configurationClassPostProcessor";

    public static final String AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME =
            "AutowiredAnnotationBeanPostProcessor";

    public static void registerAnnotationConfigProcessors(BeanDefinitionRegistry registry) {

        // 此处先实现ConfigurationClassPostProcessor
        if(!registry.containsBeanDefinition(CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME)){
            Class configurationClassPostProcessorClass = ConfigurationClassPostProcessor.class;
            BeanDefinition beanDefinition = new BeanDefinition(configurationClassPostProcessorClass,"singleton");
            registry.registerBeanDefinition(CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME,beanDefinition);
        }

        // 注册AutowiredAnnotationBeanPostProcessor
        if(!registry.containsBeanDefinition(AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)){
            Class autowiredAnnotationBeanPostProcessorClass = AutowiredAnnotationBeanPostProcessor.class;
            BeanDefinition beanDefinition = new BeanDefinition(autowiredAnnotationBeanPostProcessorClass, "singleton");
            registry.registerBeanDefinition(AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME,beanDefinition);
        }

    }

}
